<?php

namespace App\Providers;
use Phalcon\Queue\Beanstalk;

class BeanstalkServiceProvider extends AbstractServiceProvider
{
    /**
     * The Service name.
     * @var string
     */
    protected $serviceName = 'queue';

    /**
     * Register application service.
     *
     * @return void
     */
    public function register()
    {
        $this->di->setShared(
			$this->serviceName, 
			function () {
                $config = $this->getShared('config')->beanstalk->toArray();
				$queue = new Beanstalk(
						[
							"host" => $config['host'],
							"port" => $config['port'],
						]
				 );
				 
				 $queue->choose('ew_news');
				 return $queue;
			}
		);
    }
}
